<template>
	<div>
		<el-form ref="form" :model="form" :rules="rules" label-width="80px">

			<el-form-item label="管家姓名" prop="houseName">
				<el-input v-model="form.houseName"></el-input>
			</el-form-item>

			<el-form-item label="联系电话" prop="telephone">
				<el-input v-model="form.telephone"></el-input>
			</el-form-item>

			<el-form-item label="服务楼层" prop="serviceFloor">
				<el-input v-model="form.serviceFloor"></el-input>
			</el-form-item>

			<el-form-item label="备注">
				<el-input v-model="form.remarks"></el-input>
			</el-form-item>

			<el-form-item label="操作时间" prop="operationTime" >
				<el-date-picker value-format="yyyy-MM-dd" type="date" v-model="form.operationTime"
					placeholder="选择日期">
				</el-date-picker>
			</el-form-item>

			<el-form-item>
				<el-button type="primary" plain @click="save">保存数据</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
	import axios from '@/utils/axiosutils.js';
	export default {
		name: 'ServiceHouseAdd',
		props: ['editid'],
		components: {},
		data() {
			return {
				form: {
					houseName: '',
					telephone: '',
					serviceFloor: '',
					remarks: '',
					operationTime: ''
				},
				rules: {
					houseName: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					telephone: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					serviceFloor: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}],
					operationTime: [{
						required: true,
						message: '请输入',
						trigger: 'blur'
					}]
				},
				isupdate: false
			};
		},
		created() {
			if (this.editid) {
				// 如果是修改 用户名输入框禁用
				this.isupdate = true;
				axios.get(
					'/serviceHouse/getById',
					response => {
						this.form.houseId = this.editid;
						this.form.houseName = response.obj.houseName;
						this.form.telephone = response.obj.telephone;
						this.form.serviceFloor = response.obj.serviceFloor;
						this.form.remarks = response.obj.remarks;
						this.form.operationTime = response.obj.operationTime;
					}, {
						houseId: this.editid
					}
				);
			}
		},
		methods: {
			save: function() {
				axios.post(
					'/serviceHouse/add',
					resp => {
						this.$emit('update:show', false);
						this.$emit('getData');
					},
					this.form
				);
			}
		}
	};
</script>

<style scoped>
	.el-row {
		height: 60px;
	}
</style>
